﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FacturIT.Service.Repositories.PaymentType;

namespace FacturIT.Service.PaymentType
{
    internal class PaymentTypeFactory
    {
        private static PaymentTypeFactory instance = null;
        public static PaymentTypeFactory Instance
        {
            get
            {
                if (instance == null)
                    instance = new PaymentTypeFactory();
                return instance;
            }
        }

        private PaymentTypeService PaymentTypeService;
        public PaymentTypeService GetPaymentTypeService()
        {
            if (PaymentTypeService == null)
                PaymentTypeService = new PaymentTypeService();

            return PaymentTypeService;
        }
    }
    internal class PaymentTypeService
    {
        private IRepository<BLL.Model.PaymentType.PaymentType, int> repository;
        private IRepository<BLL.Model.PaymentType.PaymentType, int> Repository
        {
            get
            {
                if (repository == null)
                    repository = new PaymentTypesRepository();

                return repository;
            }
        }

        internal PaymentTypeDTO AddPaymentType(string name)
        {
            PaymentTypeDTO PaymentType = Convert(Repository.Add(new BLL.Model.PaymentType.PaymentType()
            {
                Name = name,
            }));
            return PaymentType;
        }

        internal IEnumerable<PaymentTypeDTO> ReadAllPaymentTypes()
        {
            return from paymenttype in Repository.ReadAll() select Convert(paymenttype);
        }

        internal PaymentTypeDTO ReadPaymentType(int paymentTypeID)
        {
            return Convert(((PaymentTypesRepository)Repository).ReadPaymentType(paymentTypeID));
        }

        #region HelperMethods

        private static PaymentTypeDTO Convert(BLL.Model.PaymentType.PaymentType paymentType)
        {
            return new PaymentTypeDTO(paymentType);
        }
        #endregion



        
    }


}